/* 
 *  File: AboutWindow.java
 *  Author: Edson Pereira
 *  Version: 1.0
 *  Date: 04/18/2011
 *  
 *  Oracle Certified Master Java SE 6 Developer
 *  
 *  This class is part of Java Developer Assignment CX-310-252A_1
 */
package suncertify.view;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;

/**
 * AboutWindow object is a JDialog object customized to show system information.
 * <p>Some information is common to all application like name and author
 *
 * @author Edson Pereira
 * @version 1.0
 */
/*package*/
class AboutWindow extends JDialog{
    /* Common information for all system */
    /**
     *  Application name used for all system
     */
    public static final String APPLICATION_NAME = "CRS System";
    /**
     *  System version used for all system
     */
    public static final String APPLICATION_VERSION = "Version 1.0";
    /**
     *  Author of application
     */
    public static final String AUTHOR = "Edson Pereira";
    /**
     *  Date of initial analysis
     */
    public static final String DATE = "11/25/2010";

    /* Private labels used only in AboutWindow */
    private final String AUTHOR_LABEL = "Author: " + AUTHOR;
    private final String DATE_LABEL = "DAte: " + DATE;
    private final String OK_BUTTON_LABEL = "OK";
    private final String TITLE = "About CRS System";
    
    /* Private dimension user for AboutWindow size */
    private int WIDTH_AND_HEIGHT = 200;
    
    /*
     *  Reference to parent JFrame to be used in relative location
     */
    private JFrame parentFrame;

    /**
     * Creates an instance of AboutWindow with parent {@code JFrame} 
     * 
     * @param frame Parent {@code JFrame} reference
     */
    AboutWindow(JFrame frame){
        super(frame, false);
        parentFrame = frame;
        init();
    }
    
    /**
     * Initialize all fields of AboutWindow 
     */
    private void init(){
        /* Instance fields*/
        JButton okButton = new JButton(OK_BUTTON_LABEL);

        JLabel author = new JLabel(AUTHOR_LABEL);
        JLabel date = new JLabel(DATE_LABEL);
        JLabel name = new JLabel(APPLICATION_NAME);
        JLabel version = new JLabel(APPLICATION_VERSION);

        /* Set button action listener */
        okButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                hideDialog();
            }
        });

        /* Create one FlowLayout panel for each field, each field has already
         * centralized and with space between them
         */
        JPanel namePanel = new JPanel(new FlowLayout());
        namePanel.add(name);

        JPanel versionPanel = new JPanel(new FlowLayout());
        versionPanel.add(version);

        JPanel authorPanel = new JPanel(new FlowLayout());
        authorPanel.add(author);

        JPanel datePanel = new JPanel(new FlowLayout());
        datePanel.add(date);

        JPanel buttonPanel = new JPanel(new FlowLayout());
        buttonPanel.add(okButton);

        /* Create main Panel to keep all fields together */
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
        mainPanel.add(namePanel);
        mainPanel.add(versionPanel);
        mainPanel.add(new JSeparator());
        mainPanel.add(authorPanel);
        mainPanel.add(datePanel);
        mainPanel.add(buttonPanel);

        /* Add main panel to container and set AboutWindow configuration */
        this.add(mainPanel);
        this.setTitle(TITLE);
        this.setLocationRelativeTo(parentFrame);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE );
        this.setSize(WIDTH_AND_HEIGHT, WIDTH_AND_HEIGHT);
        this.setVisible(true);
    }

    /* Hide AboutWindow */
    private void hideDialog(){
        this.setVisible(false);
    }
}
